package cn.brilliantfuture.commentry.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * Title: Veggie Home
 * 
 * Author:  LiTian  
 *
 * Date: 2012-1-18
 * 
 * Description: 日期和时间帮助类
 * 
 */
public class DateTimeHelper {
	
	/**
	 * yyyy
	 */
	public static final String DEFAULT_YEAR_FORMAT = "yyyy";
	
	/**
	 * yyyy-MM-dd HH:mm:ss
	 */
	public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	/**
	 * yyyy-MM-dd
	 */
	public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
	
	/**
	 * yyyy-MM-dd HH:mm
	 */
	public static final String DEFAULT_DATE_HM_FORMAT = "yyyy-MM-dd HH:mm";
	
	/**
	 * yyyyMMddHHmmss
	 */
	public static final String DEFAULT_DATE_TIME_NOT_SPACE_FORMAT = "yyyyMMddHHmmss";
	
	/**
	 * yyyy年MM月dd日
	 */
	public static final String DEFAULT_CN_DATE_FORMATE = "yyyy年MM月dd日";
	
	public static String dateTimeToStr(Date source, String format){
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		return dateFormat.format(source);
	}
	
	public static Date strToDateTime(String source, String format){
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		
		try {
			return dateFormat.parse(source);
		} catch (ParseException e) {
			return null;
		}
	}
}
